package cn.tedu.spring.life;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Component
public class Life {
    private String meaning;

    //1.无参构造实例化
    public Life() {
        System.out.println("1.通过无参构造实例化");
    }

    public Life(String meaning) {
        this.meaning = meaning;
    }

    public String getMeaning() {
        return meaning;
    }
    //2.set方法赋值
    @Value("世界那么大，我想去看看")
    public void setMeaning(String meaning) {
        this.meaning = meaning;
        System.out.println("2.通过set方法赋值");
    }

    @Override
    public String toString() {
        return "Life{" +
                "meaning='" + meaning + '\'' +
                '}';
    }
    //3.初始化方法
    @PostConstruct
    public void init() {
        System.out.println("3.生命周期初始化方法");
    }
    //5.销毁之前方法
    @PreDestroy
    public void destroy() {
        System.out.println("5.销毁之前方法执行的逻辑");
    }
}
